package com.example.sportgoods.controller;

import com.example.sportgoods.domain.Shop;
import com.example.sportgoods.Service.ShopService;
import com.example.sportgoods.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="店铺管理（0528王雪伊）")
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "取得所有店铺列表", notes = "取得所有店铺列表")
    @GetMapping("/list")
    private AjaxResult list(){
        List<Shop> allShop = shopService.selectAllShops();
        return AjaxResult.success(allShop);
    }
    @ApiOperation(value = "根据id查询店铺列表", notes = "根据id查询店铺列表")
    @ApiImplicitParam(name = "id", value = "店铺id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(shopService.selectShopById(id));
    }

    @ApiOperation("修改店铺信息")
    @PutMapping
    public AjaxResult edit(@RequestBody Shop shop){
        return AjaxResult.success(shopService.updateShop(shop));
    }
    @ApiOperation("新增店铺")
    @PostMapping
    public AjaxResult add(@RequestBody Shop shop) {
        shopService.addShop(shop);
        return AjaxResult.success("店铺新增成功");
    }
    // 根据店铺id删除店铺的接口
    @ApiOperation("根据id删除店铺")
    @ApiImplicitParam(name = "id", value = "店铺id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        shopService.deleteShopById(id);
        return AjaxResult.success("店铺删除成功");
    }
}
